/* Copyright (c) 2004-2024 peigen.info. All rights reserved. */

package info.peigen.hotpot.manage.core.service;

import info.peigen.hotpot.common.service.base.processor.ProcessorServiceContext;
import info.peigen.hotpot.common.service.base.processor.ProcessorServiceInvoke;
import info.peigen.hotpot.manage.core.service.facade.PositionServiceFacade;
import info.peigen.hotpot.manage.core.service.order.PositionCreateOrder;
import info.peigen.hotpot.manage.core.service.order.PositionEditOrder;
import info.peigen.hotpot.manage.core.service.result.PositionCreateResult;
import info.peigen.hotpot.manage.core.service.result.PositionEditResult;
import org.noear.solon.annotation.Component;

/**
 * <b>(PositionService)</b>
 * "职位" 服务实现
 *
 * @author Peigen
 * @version 1.0.0
 * @since 2024-06-28
 */
@SuppressWarnings({"unused", "rawtypes"})
@Component
public class PositionService extends AbstractHotpotManageService implements PositionServiceFacade {

    @Override
    public PositionCreateResult create(PositionCreateOrder order) {
        ProcessorServiceContext serviceContext = ProcessorServiceContext.builder().order(order).result(new PositionCreateResult()).build();
        execute(serviceContext, new ProcessorServiceInvoke() {
            @Override
            public void addProcessor(ProcessorServiceContext serviceContext) {
                serviceContext.addProcessors(positionCreateProcessor);
            }

            @Override
            public void addPostProcessor(ProcessorServiceContext serviceContext) {
                serviceContext.addProcessors(positionStoreProcessor, positionCreateResultProcessor);
            }
        });
        return (PositionCreateResult) serviceContext.getResult();
    }

    @Override
    public PositionEditResult edit(PositionEditOrder order) {
        ProcessorServiceContext serviceContext = ProcessorServiceContext.builder().order(order).result(new PositionEditResult()).build();
        execute(serviceContext, new ProcessorServiceInvoke() {
            @Override
            public void addPreProcessor(ProcessorServiceContext serviceContext) {
                serviceContext.addProcessors(positionActiveProcessor);
            }

            @Override
            public void addProcessor(ProcessorServiceContext serviceContext) {
                serviceContext.addProcessors(positionEditProcessor);
            }

            @Override
            public void addPostProcessor(ProcessorServiceContext serviceContext) {
                serviceContext.addProcessors(positionStoreProcessor, positionEditResultProcessor);
            }
        });
        return (PositionEditResult) serviceContext.getResult();
    }
}